import { Router } from 'express'
import documentsRouter from './documents.js'
import modelRouter from './model.js'
import chatRouter from './chat.js'
import logger from '../services/logger.js'

const router = Router()

// 添加调试中间件
router.use((req, res, next) => {
  logger.info(`Route handler: ${req.method} ${req.originalUrl}`)
  next()
})

// 测试路由
router.get('/api/test', (req, res) => {
  res.json({ message: 'API is working' })
})

// 修改路由前缀
router.use('/api/documents', documentsRouter)
router.use('/api/model', modelRouter)  // 将 ollama 相关路由合并到 model 路由
router.use('/api/chat', chatRouter)

// 404 处理
router.use((req, res) => {
  logger.warn(`404 Not Found: ${req.method} ${req.originalUrl}`)
  res.status(404).json({ 
    error: 'Not Found',
    path: req.originalUrl
  })
})

export default router 